package com.haidechizi.i18n.code.generator.common.message.translate.mapping;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * @author wangdejun
 * @create 2020/10/17 11:37
 */
public class LanguageMappingInitializing implements ApplicationListener<ContextRefreshedEvent> {

    private volatile boolean init = false;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        if (init) {
            return;
        }
        init = true;
        ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
        String[] beanNamesForType = applicationContext.getBeanNamesForType(LanguageMapping.class);
        for (String beanName : beanNamesForType) {
            LanguageMapping languageMapping = applicationContext.getBean(beanName, LanguageMapping.class);
            languageMapping.languageMappingBounding();
        }
    }
}
